package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.FictionFavoriteDAO;
import com.swlz.entity.FictionFavorite;
import com.swlz.exception.CodeException;
import com.swlz.service.FictionFavoriteService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 小说收藏
 * ClassName : com.swlz.service.impl.FictionFavoriteServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-30 20:53:11
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class FictionFavoriteServiceImpl implements FictionFavoriteService {
	
	private FictionFavoriteDAO fictionFavoriteDAO = new FictionFavoriteDAO();

	@Override
	public int add(FictionFavorite fictionFavorite) throws CodeException {
		try {
			return fictionFavoriteDAO.insertSelective(fictionFavorite);
		} catch (SQLException e) {
			throw new CodeException(500, "添加小说收藏错误",e);
		}
	}

	@Override
	public int update(FictionFavorite fictionFavorite) throws CodeException {
		try {
			return fictionFavoriteDAO.updateSelective(fictionFavorite);
		} catch (SQLException e) {
			throw new CodeException(501, "修改小说收藏错误",e);
		}
	}

	@Override
	public int delete(Long fictionFavoriteId) throws CodeException {
		try {
			return fictionFavoriteDAO.deleteById(fictionFavoriteId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除小说收藏错误",e);
		}
	}

	@Override
	public FictionFavorite get(Long fictionFavoriteId) throws CodeException {
		try {
			return fictionFavoriteDAO.selectById(fictionFavoriteId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取小说收藏失败",e);
		}
	}

	@Override
	public PageVO<FictionFavorite> page(FictionFavorite fictionFavorite, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = fictionFavoriteDAO.countByModel(fictionFavorite);
			PageVO<FictionFavorite> page = new PageVO<>(total, current, rowMax);
			return page.setList(fictionFavoriteDAO.selectByModel(fictionFavorite, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取小说收藏分页数据失败",e);
		}
	}


}
